package com.zxmc.server.mapper;

import com.zxmc.pojo.entity.Chapter;
import com.zxmc.pojo.vo.ChapterDirectoryVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ChapterMapper {
    @Insert("insert into chapter (novel_id, title, chapter_order, content)" +
            " values (#{novelId},#{title},#{chapterOrder},#{content});")
    void insert(Chapter chapter);

    @Select("select * from chapter where novel_id=#{novelId} and chapter_order=#{chapterId}")
    Chapter list(@Param("novelId") Integer novelId, @Param("chapterId") Integer chapterId);

    @Select("select id,title,chapter_order from chapter where novel_id=#{novelId} order by chapter_order")
    List<ChapterDirectoryVO> directory(Integer novelId);

    @Select("select count(*) from chapter where novel_id=#{novelId}")
    Integer getTotal(Integer novelId);

    @Select("select id from chapter")
    List<Integer> listAllIds();
}
